package com.easylinkin.linkappapi.safe.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.safe.dto.HiddenActionRecordsDTO;
import com.easylinkin.linkappapi.safe.entity.HiddenActionRecords;
import com.easylinkin.linkappapi.safe.service.HiddenActionRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2023/04/04 11:42
 * @Description: 安全管理查阅记录管理
 */
@RestController
@RequestMapping("hiddenActionRecords")
@Api(tags = "安全管理查阅记录管理")
public class HiddenActionRecordsController {
  
  @Autowired
  private HiddenActionRecordsService hiddenActionRecordsService;

  /**
   * @Description: 增加安全管理查阅记录
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @PostMapping
  @ApiOperation("增加安全管理查阅记录")
  public RestMessage insert(@RequestBody HiddenActionRecords hiddenActionRecords){
    //参数验证
    Assert.notNull(hiddenActionRecords.getActionType(),"操作类型不能为空");
    hiddenActionRecordsService.insert(hiddenActionRecords);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询安全管理查阅记录详情
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询安全管理查阅记录详情")
  public RestMessage findById(@PathVariable("id")Integer id) {
    Assert.notNull(id,"id不能为空");
    HiddenActionRecordsDTO hiddenActionRecordsDTO = hiddenActionRecordsService.findById(id);
    return RestBuilders.successBuilder().data(hiddenActionRecordsDTO).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<HiddenActionRecords> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<HiddenActionRecordsDTO> record =  hiddenActionRecordsService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

